/**
 * @team Samurai Pizza Cats
 * 1. Tom Doron
 * 2. Gal Rotem
 * 3. Dor Porat
 */
 

import ic.ast.PrettyPrint;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;

import lex.Lexer;
import lex.Token;
import pars.Calc;
import pars.ICGrammar;
import pars.Tree;

public class Main
{
	public static void main(String[] args)
	{
		Lexer lex = new Lexer();
		Calc calc = new Calc();
		List<Token> tokens = new LinkedList<Token>();
		PrettyPrint printer = new PrettyPrint();
		try {
			if (args.length > 1 && args[1].startsWith("-L")) {
				List<Token> libTokens = new LinkedList<Token>();
				lex.process(args[1].substring(2), libTokens);
				Tree libAst = calc.process(libTokens, ICGrammar.LibicRules);
				System.out.println((((ic.ast.Node)libAst.root).accept(printer)).toString());
			}
			lex.process(args[0], tokens);
			Tree ast = calc.process(tokens, ICGrammar.Rules);
			System.out.println(((ic.ast.Node)ast.root).accept(printer));				
		}
		catch (Exception e) {
			System.err.println(e);
			System.exit(1);
		}
	}
}